#!/usr/bin/perl -c

package PIPL::System::Filesystem;
use 5.006;
our $VERSION = '0.01';

=head1 NAME

PIPL::System::Path - Check the specification of filesystem

=head1 SYNOPSIS

  use PIPL::System::Filesystem;
  $fs = $PI::System::Filesystem::Self->{spec};
  print "Unix" if $PI::System::Filesystem::Self->{is_Unix};

=head1 DESCRIPTION

This singleton class provides an information about filesystem specification
implemented on currently OS.

=cut


use strict;

use base 'PIPL::Class::Base',
         'PIPL::Class::Singleton';


use PIPL::System::Config;


# List of class fields (name => {is=>ro|rw, default=>value})
use constant FIELDS => {
    spec      => { is => 'ro' },
    is_Cygwin => { is => 'ro' },
    is_Epoc   => { is => 'ro' },
    is_Mac    => { is => 'ro' },
    is_OS2    => { is => 'ro' },
    is_VMS    => { is => 'ro' },
    is_Win32  => { is => 'ro' },
};


# Returns a string representation of the application data directory
sub new {
    my $class = shift;
    $class = ref $class if ref $class;
    
    my $self = $class->SUPER::new(@_);

    # Filesystem specifications
    my %map_osname2spec = (
        cygwin  => 'Cygwin',
        dos     => 'OS2',
        epoc    => 'Epoc',
        MacOS   => 'Mac',
        MSWin32 => 'Win32',
        NetWare => 'Win32',
        os2     => 'OS2',
        symbian => 'Win32',
        Unix    => 'Unix',
        VMS     => 'VMS',
    );

    my $osname = $PIPL::System::Config::Self->{osname};
    $self->{spec} = defined $map_osname2spec{$osname} ? $map_osname2spec{$osname} : 'Unix';

    my %was;
    foreach (values %map_osname2spec) {
	next if $was{$_};
	$self->{'is_' . $_} = ($_ eq $self->{spec});
	$was{$_} = 1;
    }

    return $self;
}


# Initialize singleton instance at start
__PACKAGE__->instance;


1;


=head1 BASE CLASSES

=over 2

=item *

L<PIPL::Class::Base>

=item *

L<PIPL::Class::Singleton>

=back

=head1 CONSTRUCTOR

=over

=item new

Create new object.

  $obj = new PIPL::System::Filesystem;
  $spec = $obj->{spec};

=item instance

Return existing instance of class or create new object.

  $obj = instance PIPL::System::Filesystem;
  $spec = $obj->{spec};

=back

=head1 FIELDS

=over

=item spec

Contains the string representation of the current filesystem specification.
It is the same as the specific module name for L<File::Spec> and the one of
following values: Mac, Win32, OS2, VMS, Epoc, Win32, OS2, Cygwin, Unix.

  $spec = $PI::System::Filesystem::Self->{spec};

=item is_Cygwin

=item is_Epoc

=item is_Mac

=item is_OS2

=item is_Unix

=item is_VMS

=item is_Win32

Contains a B<1> if the current filesystem specification (L<File::Spec>
specific) is the same as method name or B<undef> otherwise.

  $PI::System::Filesystem::Self->{is_Win32} or die 'only for Windows';

=back

=head1 SEE ALSO

L<PIPL::Class::Base>, L<PIPL::Class::Singleton>.

=head1 AUTHORS

Piotr Roszatycki E<lt>dexter@debian.orgE<gt>

=head1 LICENSE

Copyright 2006-2007 by Piotr Roszatycki E<lt>dexter@debian.orgE<gt>.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

See L<http://www.perl.com/perl/misc/Artistic.html>
